//
//  JDTermViewController.swift
//  DragonWallet
//
//  Created by volantPig on 2025/2/12.
//

import UIKit

class JDTermViewController: JDBaseViewController {
    
    var containerView: UIScrollView?
    
    var contentInfo = [["条款一","我是服务条款内容"]]
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.alpha = 1
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        self.setupConfig()
        self.setupUIElements()
        // Do any additional setup after loading the view.
    }
    
    func setupConfig() {
        self.setupNavigationTitle("服务条款")
//        self.title = "什么是会员专品？"
        self.setupLeftBackItem()
    }

    func setupUIElements() {
        self.containerView = UIScrollView()
        self.view.addSubview(self.containerView!)
        self.containerView?.snp.makeConstraints({ make in
            make.leading.equalTo(self.view).offset(12)
            make.trailing.equalTo(self.view).offset(-12)
            make.bottom.equalTo(self.view).offset(-27)
            make.top.equalTo(self.view).offset(statusBarHeight+44+14)
        })
        self.containerView?.makeCorner(8)
        self.containerView?.backgroundColor = .white
        
        
        var maxY = 12.0
        for sectionArray in contentInfo {
            let titleLabel = UILabel()
            self.containerView?.addSubview(titleLabel)
            titleLabel.snp.makeConstraints { make in
                make.leading.equalTo(self.containerView!).offset(12)
                make.top.equalTo(self.containerView!).offset(maxY)
                make.trailing.equalTo(self.containerView!).offset(-12)
            }
            titleLabel.text = sectionArray.first
            titleLabel.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 15, weight: .semibold), textColor: color("#333333"))
            
            let contentLabel = UILabel()
            self.containerView?.addSubview(contentLabel)
            contentLabel.snp.makeConstraints { make in
                make.leading.equalTo(self.containerView!).offset(12)
                make.top.equalTo(titleLabel.snp.bottom).offset(6)
                make.trailing.equalTo(self.containerView!).offset(-12)
            }
            contentLabel.text = sectionArray.last
            contentLabel.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 15, weight: .regular), textColor: color("#333333"))
            self.containerView?.layoutSubviews()
            maxY = contentLabel.frame.maxY + 24.0
        }
        
        
        let scrollviewHeight = self.containerView?.frame.size.height ?? 0
        self.containerView?.contentSize = CGSize.init(width: screenWidth-24, height: max(scrollviewHeight, maxY))
        
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
